<template>
  <view class="home-container">
    <view class="foldIcon">
      <tn-icon name="unfold" v-if="!drawerOpen" size="60" :bold="true" @click="toggleDrawer"></tn-icon>
    </view>

    <!-- 主内容区域 -->
    <view class="main-content">
      <view class="logo">
        <!-- Logo -->
        <image class="logo" src="">m</image>
        
        <!-- 品牌名称 -->
        <view class="brand-name">半边集</view>
      </view>
      
      <view class="desc">
        <!-- 中文短语 -->
        <view class="chinese-phrase">「身心栖所,臻于至善」</view>
        
        <!-- 英文翻译 -->
        <view class="english-phrase">
          <view>All your wellness needs,</view>
          <view>met in one destination.</view>
        </view>
      </view>
    </view>

    <!-- 抽屉侧边栏遮罩 -->
    <view v-if="drawerOpen" class="drawer-mask" @click="closeDrawer">
      <!-- 抽屉侧边栏 -->
      <view class="drawer" @click.stop>
        <image
          src="../../static/首页/u4.png"
          mode="scaleToFill"
        />
        <view class="content">
          <!-- 侧边栏头部 -->
          <view class="drawer-header">
            <view class="drawer-logo">m</view>
            <view class="drawer-brand-name">丰边集</view>
          </view>
          
          <!-- 侧边栏菜单项 -->
          <view class="drawer-menu">
            <view class="drawer-item" @click="goCourses">療愈</view>
            <view class="drawer-item" @click="goActivities">活動</view>
            <view class="drawer-item" @click="goMy">我的</view>
          </view>
          
          <!-- 关闭按钮 -->
          <view class="drawer-close" @click="closeDrawer">
            <text class="close-icon">←</text>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const drawerOpen = ref(false);

const toggleDrawer = () => {
  drawerOpen.value = !drawerOpen.value;
};

const closeDrawer = () => {
  drawerOpen.value = false;
};

const goCourses = () => {
  closeDrawer();
  uni.navigateTo({ url: '/pages/courses/index' });
};

const goActivities = () => {
  closeDrawer();
  uni.navigateTo({ url: '/pages/activities/index' });
};

const goMy = () => {
  closeDrawer();
  uni.navigateTo({ url: '/pages/my/index' });
};
</script>

<style lang="scss" scoped>
.home-container {
  width: 100vw;
  height: 100vh;
  position: relative;
  overflow: hidden;
}

.foldIcon{
  position: absolute;
  top:calc(env(safe-area-inset-top) + 60rpx);
  left: 40rpx;
  color: #fff;
  z-index: 999;
}

// 主内容区域
.main-content {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
  position: relative;
  z-index: 1;
  color: #fff;
  .logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10rpx;
    font-size: 60rpx;
    font-weight: 400;
    image{
      height: 80rpx;
    }
  }

  .desc {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    .chinese-phrase {
      font-size: 30rpx;
      margin-bottom: 30rpx;
    }

    .english-phrase {
      font-size: 25rpx;
    }
  }
}

// 背景样式 - 使用伪元素创建分层的纹理背景
.home-container {
  background: linear-gradient(to bottom, #2a2520 0%, #2a2520 65%, #c9c4b8 65%, #e8e5db 100%);
  position: relative;
  
  // 上部深色纹理
  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 65%;
    background-image: 
      repeating-linear-gradient(
        45deg,
        transparent,
        transparent 2px,
        rgba(0, 0, 0, 0.05) 2px,
        rgba(0, 0, 0, 0.05) 4px
      ),
      repeating-linear-gradient(
        -45deg,
        transparent,
        transparent 3px,
        rgba(0, 0, 0, 0.03) 3px,
        rgba(0, 0, 0, 0.03) 6px
      );
    opacity: 0.6;
    z-index: 0;
  }
  
  // 下部浅色纹理
  &::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 35%;
    background-image: 
      repeating-linear-gradient(
        90deg,
        transparent,
        transparent 4px,
        rgba(0, 0, 0, 0.02) 4px,
        rgba(0, 0, 0, 0.02) 8px
      );
    opacity: 0.4;
    z-index: 0;
  }
}

// 抽屉侧边栏遮罩
.drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 2000;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

// 抽屉侧边栏
.drawer {
  position: relative;
  width: 200rpx;
  border: 1px solid rgba(255, 255, 255, 0.3); /* 可选：添加边框增加层次感 */
  height: 100%;
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
  animation: slideIn 0.3s ease;

  image{
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
  .content{
    box-sizing: border-box;
    padding: 40rpx;
    font-size: 40rpx;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px); /* Safari 兼容 */
    border-right: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);

    .drawer-header {
      padding: 60rpx 0;
      border-bottom: 1px solid rgba(0, 0, 0, 0.08);
      display: flex;
      flex-direction: column;
      align-items: center;
      color: #fff;
      gap: 16rpx;

      .drawer-logo{
        max-height: 50rpx;
      }
      .drawer-brand-name{
        font-size: 35rpx;
        font-weight: 400;
      }
    }
  .drawer-menu {
    flex: 1;
    padding: 40px 0;
    display: flex;
    flex-direction: column;
    gap: 30rpx;

    .drawer-item {
      padding: 30rpx 0;
      font-size: 35rpx;
      color: #2a2520;
      font-weight: 400;
      transition: all 0.2s ease;
      cursor: pointer;
      font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', sans-serif;

      &:active {
        background: rgba(0, 0, 0, 0.05);
        transform: translateX(4px);
      }
    }
    }

    .drawer-close {
      padding: 20px 40px 40px;
      cursor: pointer;

      .close-icon {
        font-size: 24px;
        color: #666;
        transition: all 0.2s ease;

        &:active {
          color: #2a2520;
          transform: translateX(-4px);
        }
      }
    }
  }
}

@keyframes slideIn {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(0);
  }
}
</style>
